package com.lushu.chapitre1.dialogue.nodes
{
	import __AS3__.vec.Vector;
	
	import com.lushu.chapitre1.dialogue.api.INode;
		
	public class AbstractNode implements INode
	{
		private var parent_ : INode;
		private var name_ : String;
		protected var displayName_ : String;
		protected var type_ : String;
		protected var data_ : String;
		protected var children_ : Vector.<INode>;
		
		public function AbstractNode()
		{
			children_ = new Vector.<INode>();
		}
		
		public function addChild(node : INode) :void
		{
			node.parent = this;
			children_.push(node);
		}
		
		public function removeChild(node : INode) :void
		{
			var idx : int = children_.indexOf(node);
			if(idx != -1)
			{
				node.parent = null;
				children_.splice(idx, 1);
			}
		}
		
		public function removeChildAt(idx : int) :void
		{
			if(idx != -1)
			{
				var node : INode = children_[idx];
				node.parent = null;
				children_.splice(idx, 1);
			}
		}
		
		public function addChildAt(node : INode, idx : int ) :void
		{
			node.parent = this;
			children_.splice(idx, 0, node);
		}
		
		public function getPotentialChildNodes(node : INode) : Array
		{
			return null;	
		}
		
		public function replaceChild(prevNode : INode, newNode : INode) : void
		{
			var idx : int = children_.indexOf(prevNode);
			if(idx != -1)
			{
				prevNode.parent = null;
				newNode.parent = this;
				children.splice(idx, 1, newNode);
			} 	
		}
		
		public function switchToSwitchNode() : void
		{
			var switchNode : SwitchNode = new SwitchNode();
			var parent : INode = this.parent;
			if(parent != null)
			{
				parent.replaceChild(this, switchNode);
				switchNode.addChild(this);
			}
		}
		
		public function toXML(level : int = 0) : String
		{
			return "";
		}
		
		public function setInformation(value : XML) : void
		{
			
		}
		
		public function set parent(value : INode) : void
		{
			parent_ = value;
		}
		
		public function set data(value : String) : void
		{
			data_ = value;
		}
		
		public function get parent() : INode
		{
			return parent_;
		}
		
		public function get data() : String
		{
			return data_;
		}
		
		public function get displayName() : String
		{
			return displayName_;
		}
		
		public function set name(value : String) : void
		{
			name_ = value;
		}
		
		public function get name() :String
		{
			return name_;
		}
		
		public function get type() : String
		{
			return type_;
		}
		
		public function get children() : Vector.<INode>
		{
			return children_;
		}

	}
}